package com.log4jviewer.domain;

/**
 * Class represents list of log fields' names and gets information about entrance log.
 * 
 * @author <a href="mailto:rd.ryly@gmail.com">Ruslan Diachenko</a>
 */
public enum LogField {

    LEVEL("Level"),
    CATEGORY("Category"),
    MESSAGE("Message"),
    LINE("Line"),
    DATE("Date"),
    NDC("NDC"),
    THROWABLE("Throwable");

    private String name;

    private LogField(final String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public String getFieldInfo(final LogEvent log) {
        String fieldInfo = "";

        switch (this) {
        case LEVEL:
            fieldInfo = log.getLevel();
            break;
        case CATEGORY:
            fieldInfo = log.getCategoryName();
            break;
        case MESSAGE:
            fieldInfo = log.getMessage();
            break;
        case LINE:
            fieldInfo = log.getLineNumber();
            break;
        case DATE:
            fieldInfo = log.getDate();
            break;
        case NDC:
            fieldInfo = log.getNdc();
            break;
        case THROWABLE:
            fieldInfo = log.getThrowableInfo();
            break;
        default:
            // no code
        }
        return fieldInfo;
    }
}
